class Animal {
    String name;
    int age;
    public Animal(String name, int age) {
        this.name = name;
        this.age = age;
    }
    public void eat(){
        System.out.println(name + "吃饭~~~");
    }
}
class Cat extends Animal{

    public Cat(String name, int age) {
        super(name, age);
    }
    public void eat(){
        System.out.println(name + "吃鱼~~~");
    }
}
class Dog extends Animal{

    public Dog(String name, int age) {
        super(name, age);
    }
    public void eat(){
        System.out.println(name + "吃骨头~~~");
    }
    public void bark() {
        System.out.println(name + "旺旺~~~");
    }
}
public class TestAnimal {
    public static void main(String[] args) {
      Cat cat = new Cat("元宝",2);
      Dog dog = new Dog("小七",1);

      //向上转型
        Animal animal = cat;
        animal.eat();
        animal = dog;
        animal.eat();


        dog = (Dog) animal;
        dog.bark();
//        cat = (Cat) animal;
        cat.eat();
    }
}
